﻿using System;
using System.Collections.Generic;
using System.Transactions;
using EstimateTracker.Domain.Entities;

namespace EstimateTracker.DataAccess.Repositories
{
    public class ProjectRepository : IProjectRepository
    {
        private readonly IPersistenceManager _persistenceManager;

        public ProjectRepository(IPersistenceManager persistenceManager)
        {
            if (persistenceManager == null) throw new ArgumentNullException("persistenceManager");
            _persistenceManager = persistenceManager;
        }
        
        public IEnumerable<Project> FindAll()
        {
            return _persistenceManager.BuildCriteria<Project>().List<Project>();
        }

        public void Save(Project project)
        {
            using (var scope = new TransactionScope())
            {
                _persistenceManager.Persist(project);
                scope.Complete();
            }
        }
    }
}